<?php
/*
 * 验证码图片控制器
 */

class Controller_Checkcode extends Controller 
{
	/*
	 * 默认入口，调用png()显示验证码图片
	 *
	 * @return void
	 */
	public function action_index ()
	{
		$this->action_png();
	}

	/*
	 * 自定义PNG图片输出大小入口
	 *
	 * @param	int	$width  图片宽度
	 * @param	int	$height 图片高度
	 *
	 * @return	void
	 */
	public function action_png ($width = 160, $height = 60)
	{
		$img = new Securimage();
		
		// Change some settings
		$img->image_width  = $width <= 300 && $width >= 100 ? $width : 160;
		$img->image_height = $height <= 100 && $height <= 30 ? $height : 60;
		$img->perturbation = 0.6; // 1.0 = high distortion, higher numbers = more distortion
		$img->image_bg_color = new Securimage_Color("#FFFFFF");
		$img->text_color = new Securimage_Color("#000000");
		$img->text_transparency_percentage = 15; // 100 = completely transparent
		$img->num_lines = 2;
		$img->line_color = new Securimage_Color("#000000");
		$img->signature_color = new Securimage_Color(rand(0, 128), rand(64, 128), rand(128, 255));
		$img->image_type = SI_IMAGE_PNG;
		
		$img->show(); 
	}
}
